package com.letoo.dragon.core.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.letoo.dragon.common.utils.JPushUtils;
import com.letoo.dragon.core.service.JPushService;

import cn.jpush.api.push.PushResult;

/**
 * 激光推送服务接口实现
 * 
 * @author: dengjie
 */
@Service("jPushService")
public class JPushServiceImpl implements JPushService {

    @Value("${jpush.masterSecret}")
    private String masterSecret;

    @Value("${jpush.appKey}")
    private String appKey;

    @Override
    public boolean sendMsgByAlias(String alias, String title, String msgContent, Map<String, String> extras) {
        PushResult result = JPushUtils.sendMsgByAlias(masterSecret, appKey, alias, title, msgContent, extras);
        return result.isResultOK();
    }

    @Override
    public boolean sendMsgByRegistrationId(String registrationId, String title, String msgContent,
            Map<String, String> extras) {
        PushResult result = JPushUtils.sendMsgByRegistrationId(masterSecret, appKey, registrationId, title, msgContent,
                extras);
        return result.isResultOK();
    }

    @Override
    public boolean sendMsgByTag(String tag, String title, String msgContent, Map<String, String> extras) {
        PushResult result = JPushUtils.sendMsgByTag(masterSecret, appKey, tag, title, msgContent, extras);
        return result.isResultOK();
    }

    @Override
    public boolean sendNotificationByAlias(String alias, String title, String sound, String msgContent,
            Map<String, String> extras) {
        PushResult result = JPushUtils.sendNotificationByAlias(masterSecret, appKey, alias, title, sound, msgContent,
                extras);
        return result.isResultOK();
    }

    @Override
    public boolean sendNotificationByRegistrationId(String registrationId, String title, String sound,
            String msgContent, Map<String, String> extras) {
        PushResult result = JPushUtils.sendNotificationByRegistrationId(masterSecret, appKey, registrationId, title, sound,
                msgContent, extras);
        return result.isResultOK();
    }

    @Override
    public boolean sendNotificationByTag(String tag, String title, String sound, String msgContent,
            Map<String, String> extras) {
       PushResult result = JPushUtils.sendNotificationByTag(masterSecret, appKey, tag, title, sound, msgContent,
                extras);
        return result.isResultOK();
    }

}
